package net.sx.minemodule.mvp.presenters;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;
import com.kedll.library.util.Log;
import com.kedll.library.util.ToastUtil;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.mvp.bean.GoodCollectBean;
import net.sx.minemodule.mvp.item.GoodCollectItem;

import java.util.List;

/**
 * 商品收藏
 *
 * @author 11470
 */
public class MineGoodCollectPresenter extends AbstractRefreshPresenter<RefreshingView> {

    List<GoodCollectBean> goodCollectBean;
    private int pos = 1;

    public MineGoodCollectPresenter(RefreshingView mView) {
        super(mView);
//        mItem=new GoodCollectItem();

    }

    public void removeGoodsItem(GoodCollectItem iItem) {
        MineApiUtils.removeMyCollectionGoods(iItem.getData().getSid(), o -> {
            adapter.removeItem(iItem);
            adapter.notifyDataSetChanged();
        }, throwable -> {

        });
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        if (isLoadMore) {
            pos++;
        }
        MineApiUtils.getMyCollectionGoodsList(pos, subModelList -> {
            if (TextUtils.isEmpty(subModelList.getItems())) {
                return;
            }
            goodCollectBean = JSON.parseArray(subModelList.getItems(), GoodCollectBean.class);
            parserData(isLoadMore, goodCollectBean);
        }, throwable -> {

        });
    }

}
